var config={"cookieLife":30,"timeout":30000};
var Page = function() {
    return {
        init: function() {
        	Page.initShow();
        	Page.initBing();
        },
        setOuterBox: function() {
            var c = $(".page-container > .side");
            var b = function() {
                var f = c.length ? (c.outerHeight() + $("#featurebar").outerHeight() + 20) : 0;
                var d = Math.max(f, $(window).height());
                if (navigator.userAgent.indexOf("MSIE 8.0") >= 0) {
                    d -= 40
                }
                $(".page-container").css("min-height", d)
            };
            c.resize(b);
            $(window).resize(b);
            b()
        },
        toggleSearch: function() {
            $("#bysearchTab").toggle(function() {
            	 $("#bysearchTab").removeClass("active");
                 $("#querybox").removeClass("show")

            },
            function() {
            	 $("#bysearchTab").addClass("active");
                 $("#querybox").addClass("show")
            })

        },
        toggleTreeBox: function() {
            var b = $(".side-handle").data("id");
            if (typeof b == "undefined" || b == null) {
                return
            }
            if ($.cookie(b) == "hide") {
                Page.hideTreeBox(b)
            }
            $(".side-handle").toggle(function() {
                if ($.cookie(b) == "hide") {
                    return Page.showTreeBox(b)
                }
                Page.hideTreeBox(b)
            },
            function() {
                if ($.cookie(b) == "show") {
                    return  Page.hideTreeBox(b)
                }
                Page.showTreeBox(b)
            });
            setTimeout(function() { $(".page-container.with-side").addClass("with-transition")},1000)
        },
        setTreeBox: function() {
            if ($(".page-container > .side").length) {
                $(".page-container").addClass("with-side")
            }
            Page.toggleTreeBox()
        },
        hideTreeBox: function(b) {
            $.cookie(b, "hide", {
                expires: config.cookieLife,
                path: config.webRoot
            });
            $(".page-container").addClass("hide-side");
            $(".side-handle .fa-caret-left").removeClass("fa-caret-left").addClass("fa-caret-right");
        },
        showTreeBox: function(b) {
            $.cookie(b, "show", {
                expires: config.cookieLife,
                path: config.webRoot
            });
            $(".page-container").removeClass("hide-side");
            $(".side-handle .fa-caret-right").removeClass("fa-caret-right").addClass("fa-caret-left");
        },
        initShow:function(){
        	Page.setOuterBox();
            Page.setTreeBox();
            Page.toggleSearch()
        },
        initBing:function($container){


        	if ($container == undefined) {
				$container = $("body")
			}

        	$('button[data-toggle="edit-button"]',$container).each(function() {
        		var h = $(this);

				h.unbind('click');
				h.bind('click',function(){
					Global.popWin('编辑窗口','/admin/sys/menu/create');
				});
        	});

        }
    }
} ();